package com.yuyou.fn.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.balance.entity.BalanceTransfer;
import com.yuyou.fn.balance.entity.BalanceWithdrawal;
import com.yuyou.fn.balance.entity.TmsBalanceTransfer;
import com.yuyou.fn.balance.service.IBalanceTransferService;
import com.yuyou.fn.balance.service.IBalanceWithdrawalService;
import com.yuyou.fn.balance.service.ITmsBalanceTransferService;
import com.yuyou.fn.balance.vo.BalanceTransferQueryVo;
import com.yuyou.fn.balance.vo.BalanceWithdrawalQueryVo;
import com.yuyou.fn.balance.vo.TmsBalanceTransferQueryVo;
import com.yuyou.fn.balance.vo.TmsStudentAccount;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.common.util.BigDecimals;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.common.util.Utils;
import com.yuyou.fn.educational.entity.Campus;
import com.yuyou.fn.educational.entity.Student;
import com.yuyou.fn.educational.service.ICampusService;
import com.yuyou.fn.educational.service.IStudentService;
import com.yuyou.fn.platform.permission.DataPermission;
import com.yuyou.fn.report.entity.StudentBalance;
import com.yuyou.fn.report.service.IStudentBalanceService;
import com.yuyou.fn.report.vo.StudentBalanceQueryVo;
import com.yuyou.fn.settlement.entity.AccountRecharge;
import com.yuyou.fn.settlement.service.IAccountRechargeService;
import com.yuyou.fn.settlement.service.impl.AccountRechargeServiceImpl;
import com.yuyou.fn.settlement.vo.AccountRechargeDetailVo;
import com.yuyou.fn.settlement.vo.AccountRechargeQueryVo;
import com.yuyou.fn.util.Webs;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wens on 2017/4/16.
 */
@Controller
@RequestMapping("/api/admin/balance")
public class AdminBalanceController extends ApiBaseController {


    @Resource
    private IBalanceTransferService balanceTransferService;

    @Resource
    private IBalanceWithdrawalService balanceWithdrawalService;

    @Resource
    private ITmsBalanceTransferService tmsBalanceTransferService;

    @Resource
    private IAccountRechargeService accountRechargeService;

    @Resource
    private ICampusService campusService;

    @Resource
    private IStudentService studentService;

    @Resource
    private IStudentBalanceService studentBalanceService;

    @ApiOperation("余额充值")
    @RequestMapping(value = "/rechargeBalance", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> rechargeBalance(@RequestParam("studentId") long studentId , @RequestParam("campusId") long campusId ,@RequestParam("remark") String remark,@RequestParam("amount")BigDecimal amount ) {
        Campus campus=campusService.findById(campusId);
        Long requestPayId=accountRechargeService.rechargeBalance(campus.getAreaTeamId(),studentId,campusId,campus.getCampusName(),amount,remark);
        return ReturnResult.success(requestPayId) ;
    }


    @ApiOperation("学生账户余额申请提现")
    @RequestMapping(value = "/withdrawalForStudent", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> withdrawalForStudent(@RequestParam(value = "applierMainAccountId" ) Long applierMainAccountId ,@RequestParam(value = "acceptCampusId" ) Long acceptCampusId , @RequestParam(value = "amount" )BigDecimal amount,@RequestParam(value = "bankName" ) String bankName,@RequestParam(value = "bankCity" ) String bankCity,@RequestParam(value = "cardUser" ) String cardUser,@RequestParam(value = "cardNo" ) String cardNo,@RequestParam(value = "reasonRemark" ) String reasonRemark) {
        BalanceWithdrawal balanceWithdrawal=balanceWithdrawalService.saveBalanceWithdrawal(getCurrentSysPrincipal(),applierMainAccountId , acceptCampusId ,  amount,bankName,bankCity,cardUser,cardNo,reasonRemark);
        return ReturnResult.success(balanceWithdrawal.getBalanceWithdrawalId()) ;
    }

    @ApiOperation("提现审核列表")
    @ApiImplicitParams({@ApiImplicitParam(value = "areaTeamId" ,required = false),@ApiImplicitParam(value = "applierMainAccountName" ,required = false),@ApiImplicitParam(value = "operatorName" ,required = false),@ApiImplicitParam(value = "status" ,required = false),@ApiImplicitParam(value = "payStatus" ,required = false),@ApiImplicitParam(value = "extra" ,required = false),@ApiImplicitParam(value = "startTime" ,required = false),@ApiImplicitParam(value = "endTime" ,required = false)})
    @RequestMapping(value = "/withdrawalList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<BalanceWithdrawal>> withdrawalList(BalanceWithdrawalQueryVo balanceWithdrawalQueryVo , @RequestParam(value = "pageNo" , defaultValue = "1") Integer pageNo , @RequestParam(value = "pageSize" , defaultValue = "20") Integer pageSize , HttpServletRequest request ) {
        DataPermission dataPermission = getDataPermission(request);
        List<Long> campusIds = dataPermission.getCampusIds();
        Page<BalanceWithdrawal> page = balanceWithdrawalService.findBalanceWithdrawalByQuery(balanceWithdrawalQueryVo,campusIds, pageNo , pageSize);
        return ReturnResult.success(page) ;
    }


    @ApiOperation("审核提现")
    @RequestMapping(value = "/auditWithdrawal", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> auditWithdrawal(@RequestParam("balanceWithdrawalId") Long balanceWithdrawalId , @RequestParam("status") Integer status ,@RequestParam("auditRemark") String auditRemark ) {
        balanceWithdrawalService.audit(balanceWithdrawalId , status ,auditRemark  ,getCurrentSysPrincipal());
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("设置支付状态(提现)")
    @RequestMapping(value = "/setupPayStatusForWithdrawal", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> auditWithdrawal(@RequestParam("balanceWithdrawalId[]") Long[] balanceWithdrawalIds ) {
        balanceWithdrawalService.setupPayStatus(balanceWithdrawalIds,getCurrentSysPrincipal());
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("提现申请详情")
    @RequestMapping(value = "/withdrawalDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<BalanceWithdrawal> withdrawalDetail(@RequestParam("balanceWithdrawalId") Long balanceWithdrawalId ) {
        BalanceWithdrawal balanceWithdrawal = balanceWithdrawalService.findById(balanceWithdrawalId);
        return ReturnResult.success(balanceWithdrawal) ;
    }



    @ApiOperation("学生账户余额申请转让")
    @RequestMapping(value = "/transferForStudent", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> transferForStudent(@RequestParam(value = "applierMainAccountId" ) Long applierMainAccountId,@RequestParam(value = "destMainAccountId" ) Long destMainAccountId ,@RequestParam(value = "acceptCampusId" ) Long acceptCampusId , @RequestParam(value = "amount" )BigDecimal amount,@RequestParam(value = "reasonRemark" ) String reasonRemark) {
        balanceTransferService.save(getCurrentSysPrincipal() , applierMainAccountId,destMainAccountId ,acceptCampusId , amount,reasonRemark);
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("转让审核列表")
    @ApiImplicitParams({@ApiImplicitParam(value = "areaTeamId" ,required = false),@ApiImplicitParam(value = "applierMainAccountName" ,required = false),@ApiImplicitParam(value = "operatorName" ,required = false),@ApiImplicitParam(value = "status" ,required = false),@ApiImplicitParam(value = "extra" ,required = false),@ApiImplicitParam(value = "startTime" ,required = false),@ApiImplicitParam(value = "endTime" ,required = false)})
    @RequestMapping(value = "/transferList", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<BalanceTransfer>> transferList(BalanceTransferQueryVo  balanceTransferQueryVo , @RequestParam(value = "pageNo" , defaultValue = "1") Integer pageNo , @RequestParam(value = "pageSize" , defaultValue = "20") Integer pageSize , HttpServletRequest request ) {
        DataPermission dataPermission = getDataPermission(request);
        List<Long> campusIds = dataPermission.getCampusIds();
        Page<BalanceTransfer> page = balanceTransferService.findBalanceTransferByQuery(balanceTransferQueryVo,campusIds, pageNo , pageSize);
        return ReturnResult.success(page) ;
    }

    @ApiOperation("审核转让")
    @RequestMapping(value = "/auditTransfer", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> auditTransfer(@RequestParam("balanceTransferId") Long balanceTransferId , @RequestParam("status") Integer status ,@RequestParam("auditRemark") String auditRemark ) {
        balanceTransferService.audit(balanceTransferId , status,auditRemark ,getCurrentSysPrincipal());
        return ReturnResult.success("OK") ;
    }

    @ApiOperation("转让申请详情")
    @RequestMapping(value = "/transferDetail", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<BalanceTransfer> transferDetail(@RequestParam("balanceTransferId") Long balanceTransferId ) {
        BalanceTransfer balanceTransfer = balanceTransferService.findById(balanceTransferId);
        return ReturnResult.success(balanceTransfer) ;
    }


    @ApiOperation("导出提现申请")
    @RequestMapping(value = "/exportWithdrawalList", method = { RequestMethod.GET, RequestMethod.POST })
    public void exportWithdrawalList(BalanceWithdrawalQueryVo balanceWithdrawalQueryVo  , HttpServletRequest request, HttpServletResponse response) throws IOException {

        DataPermission dataPermission = getDataPermission(request);
        List<Long> campusIds = dataPermission.getCampusIds();
        Page<BalanceWithdrawal> page = balanceWithdrawalService.findBalanceWithdrawalByQuery(balanceWithdrawalQueryVo, campusIds, 1, 100000);

        SXSSFWorkbook excel = new SXSSFWorkbook();

        SXSSFSheet sheet = excel.createSheet("提现");

        SXSSFRow firstRow = sheet.createRow(0);

        String[] titles = new String[] { "学生姓名","学生编号","提现金额","申请时间","申请人","转账银行","转账账号","开户城市","开户人姓名","审核人","审核时间","审核状态","支付状态","支付人","支付时间","受理校区","审核原因"} ;

        for (int i = 0; i < titles.length; i++) {

            SXSSFCell cell = firstRow.createCell(i);
            cell.setCellValue(titles[i]);
        }

        List<BalanceWithdrawal> balanceWithdrawals = page.getRecords();

        Map<String,String> statusMap = new HashMap<>();
        statusMap.put("0","审核中");
        statusMap.put("1","已审核");
        statusMap.put("2","驳回审核");


        Map<String,String> payStatusMap = new HashMap<>();
        payStatusMap.put("0","未支付");
        payStatusMap.put("1","已支付");

        for (int i = 0; i < balanceWithdrawals.size(); i++ ) {

            SXSSFRow row = sheet.createRow(i + 1);

            BalanceWithdrawal balanceWithdrawal = balanceWithdrawals.get(i);
            JSONObject extra = JSONObject.parseObject( balanceWithdrawal.getExtra() );

            int c = 0;
            SXSSFCell cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getApplierMainAccountName());

            cell = row.createCell(c++);
            cell.setCellValue(extra.getString("studentNo"));

            cell = row.createCell(c++);
            cell.setCellType(CellType.NUMERIC);
            cell.setCellValue(Double.parseDouble(BigDecimals.formatBigDecimal(balanceWithdrawal.getAmount(),"0.00")));

            cell = row.createCell(c++);
            cell.setCellValue(Utils.formatDate( balanceWithdrawal.getCreateTime() , "yyyy-MM-dd HH:mm:ss"));

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getOperatorName());

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getBankName());

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getCardNo());

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getBankCity());

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getCardUser());

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getAuditName());

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getAuditTime() == null ? StringUtils.EMPTY : Utils.formatDate( balanceWithdrawal.getAuditTime() , "yyyy-MM-dd HH:mm:ss"));

            cell = row.createCell(c++);
            cell.setCellValue(statusMap.get(balanceWithdrawal.getStatus().toString()));

            cell = row.createCell(c++);
            cell.setCellValue(payStatusMap.get(balanceWithdrawal.getPayStatus().toString()));





            cell = row.createCell(c++);
            cell.setCellValue(StringUtils.defaultString(balanceWithdrawal.getPayPersonName()));

            cell = row.createCell(c++);
            cell.setCellValue(balanceWithdrawal.getPayTime() == null ? StringUtils.EMPTY : Utils.formatDate( balanceWithdrawal.getPayTime() , "yyyy-MM-dd HH:mm:ss"));

            cell = row.createCell(c++);
            cell.setCellValue(StringUtils.defaultString(balanceWithdrawal.getAcceptCampusName()));

            cell = row.createCell(c++);
            cell.setCellValue(StringUtils.defaultString(balanceWithdrawal.getAuditRemark()));

        }

        Webs.writeExcel(request,response, excel , "提现申请" ) ;

    }

    @ApiOperation("导出转让申请")
    @RequestMapping(value = "/exportTransferList", method = { RequestMethod.GET, RequestMethod.POST })
    public void exportTransferList(BalanceTransferQueryVo balanceTransferQueryVo , HttpServletRequest request, HttpServletResponse response) throws IOException {


        DataPermission dataPermission = getDataPermission(request);
        List<Long> campusIds = dataPermission.getCampusIds();
        Page<BalanceTransfer> page = balanceTransferService.findBalanceTransferByQuery(balanceTransferQueryVo, campusIds, 1, 100000);

        SXSSFWorkbook excel = new SXSSFWorkbook();

        SXSSFSheet sheet = excel.createSheet("转让");

        SXSSFRow firstRow = sheet.createRow(0);

        String[] titles = new String[] { "学生姓名","学生编号","转让金额","转让学生姓名","转让学生学号","转让学生电话","申请时间","申请人","审核人","审核时间","审核状态"} ;

        for (int i = 0; i < titles.length; i++) {

            SXSSFCell cell = firstRow.createCell(i);
            cell.setCellValue(titles[i]);
        }

        List<BalanceTransfer> balanceTransfers = page.getRecords();

        Map<String,String> statusMap = new HashMap<>();
        statusMap.put("0","审核中");
        statusMap.put("1","已审核");
        statusMap.put("2","驳回审核");


        for (int i = 0; i < balanceTransfers.size(); i++ ) {

            SXSSFRow row = sheet.createRow(i + 1);

            BalanceTransfer balanceTransfer = balanceTransfers.get(i);
            JSONObject extra = JSONObject.parseObject( balanceTransfer.getExtra() );

            int c = 0;
            SXSSFCell cell = row.createCell(c++);
            cell.setCellValue(balanceTransfer.getApplierMainAccountName());

            cell = row.createCell(c++);
            cell.setCellValue(extra.getString("studentNo"));

            cell = row.createCell(c++);
            cell.setCellValue(BigDecimals.formatBigDecimal(balanceTransfer.getAmount(),"0.00"));

            cell = row.createCell(c++);
            cell.setCellValue(balanceTransfer.getDestMainAccountName());

            cell = row.createCell(c++);
            cell.setCellValue(extra.getString("destStudentNo"));

            cell = row.createCell(c++);
            cell.setCellValue(extra.getString("destPhoneNo"));

            cell = row.createCell(c++);
            cell.setCellValue(Utils.formatDate( balanceTransfer.getCreateTime() , "yyyy-MM-dd HH:mm:ss"));

            cell = row.createCell(c++);
            cell.setCellValue(balanceTransfer.getOperatorName());

            cell = row.createCell(c++);
            cell.setCellValue(balanceTransfer.getAuditName());

            cell = row.createCell(c++);
            cell.setCellValue(balanceTransfer.getAuditTime() == null ? StringUtils.EMPTY : Utils.formatDate( balanceTransfer.getAuditTime() , "yyyy-MM-dd HH:mm:ss"));

            cell = row.createCell(c++);
            cell.setCellValue(statusMap.get(balanceTransfer.getStatus().toString()));

        }

        Webs.writeExcel(request,response, excel , "转让申请"  ) ;

    }

    @ApiOperation("查询学生余额")
    @RequestMapping(value = "/queryStudentDealBalance", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<TmsStudentAccount> queryStudentDealBalance(@RequestParam("studentId")long studentId) {
        TmsStudentAccount result=tmsBalanceTransferService.queryStudentDealBalance(studentId);
        return ReturnResult.success(result) ;
    }

    @ApiOperation("确认余额迁移")
    @RequestMapping(value = "/comfirmTransferTmsBalance", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> comfirmTransferTmsBalance(@RequestParam("studentId")long studentId,@RequestParam("amount")BigDecimal amount) {
        tmsBalanceTransferService.comfirmTransferTmsBalance(studentId,amount);
        return ReturnResult.success("ok") ;
    }


    @ApiOperation("余额迁移列表")
    @RequestMapping(value = "/findCompleteTmsBalanceTransferPage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<TmsBalanceTransfer>> findCompleteTmsBalanceTransferPage(@ModelAttribute TmsBalanceTransferQueryVo tmsBalanceTransferQueryVo, @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
        if (tmsBalanceTransferQueryVo.getEndDate()!=null){
            tmsBalanceTransferQueryVo.setEndDate(TimeUtils.changeOneDateLastTime(tmsBalanceTransferQueryVo.getEndDate()));
        }
        Page<TmsBalanceTransfer> outBalanceTransferPage=tmsBalanceTransferService.findCompleteTmsBalanceTransferPage(tmsBalanceTransferQueryVo,pageNo,pageSize);
        return ReturnResult.success(outBalanceTransferPage) ;
    }

    @ApiOperation("导出余额迁移记录")
    @RequestMapping(value = "/exportCompleteTmsBalanceTransfer", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportCompleteTmsBalanceTransfer(@ModelAttribute TmsBalanceTransferQueryVo tmsBalanceTransferQueryVo,HttpServletRequest request,HttpServletResponse response) throws IOException {
        if (tmsBalanceTransferQueryVo.getEndDate()!=null){
            tmsBalanceTransferQueryVo.setEndDate(TimeUtils.changeOneDateLastTime(tmsBalanceTransferQueryVo.getEndDate()));
        }
        Webs.writeExcel(request, response, tmsBalanceTransferService.exportCompleteTmsBalanceTransfer(tmsBalanceTransferQueryVo), "余额迁移");
        return ReturnResult.success("ok") ;
    }


    @ApiOperation("充值列表")
    @RequestMapping(value = "/findRechargePage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Page<AccountRechargeDetailVo>> findRechargePage(@ModelAttribute AccountRechargeQueryVo accountRechargeQueryVo,  @RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
        Page<AccountRecharge> page=accountRechargeService.findPageByQuery(accountRechargeQueryVo,pageNo,pageSize);
        Page<AccountRechargeDetailVo> accountRechargeDetailVoPage=Utils.newPage(page);

        List<AccountRecharge> accountRechargeList=page.getRecords();
        List<Long>  mainAccountIds=BeanUtils.toList(accountRechargeList,"mainAccountId");
        if (Utils.checkListNotEmpty(mainAccountIds)){
            List<Student> studentList=studentService.findByIds(mainAccountIds);
            List<AccountRechargeDetailVo> accountRechargeDetailVoList=new ArrayList<>(accountRechargeList.size());
            Map<Long, Student> studentMap = BeanUtils.toMap(studentList, "studentId");
            for (AccountRecharge accountRecharge:accountRechargeList){
                AccountRechargeDetailVo accountRechargeDetailVo=new AccountRechargeDetailVo();
                BeanUtils.copyProperties(accountRechargeDetailVo,accountRecharge);
                Student student=studentMap.get(accountRecharge.getMainAccountId());
                if (student!=null){
                    accountRechargeDetailVo.setPhoneNo(student.getPhoneNo());
                    accountRechargeDetailVo.setStudentNo(student.getStudentNo());
                }
                accountRechargeDetailVoList.add(accountRechargeDetailVo);
            }
            accountRechargeDetailVoPage.setRecords(accountRechargeDetailVoList);
        }
        return ReturnResult.success(accountRechargeDetailVoPage) ;
    }


    @ApiOperation("取消充值订单")
    @RequestMapping(value = "/cancelRecharge", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> cancelRecharge(@RequestParam("accountRechargeId")long accountRechargeId) {
        accountRechargeService.cancelAccountRecharge(accountRechargeId);
        return ReturnResult.success("ok") ;
    }

    @ApiOperation("导出充值列表")
    @RequestMapping(value = "/exportRecharge", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportRecharge(@ModelAttribute AccountRechargeQueryVo accountRechargeQueryVo,HttpServletRequest request,HttpServletResponse response) throws IOException {
        Page<AccountRecharge> page=accountRechargeService.findPageByQuery(accountRechargeQueryVo,1,50000);


        List<AccountRecharge> accountRechargeList=page.getRecords();
        List<Long>  mainAccountIds=BeanUtils.toList(accountRechargeList,"mainAccountId");
        List<AccountRechargeDetailVo> accountRechargeDetailVoList=new ArrayList<>();
        if (Utils.checkListNotEmpty(mainAccountIds)){
            List<Student> studentList=studentService.findByIds(mainAccountIds);
            Map<Long, Student> studentMap = BeanUtils.toMap(studentList, "studentId");
            for (AccountRecharge accountRecharge:accountRechargeList){
                AccountRechargeDetailVo accountRechargeDetailVo=new AccountRechargeDetailVo();
                BeanUtils.copyProperties(accountRechargeDetailVo,accountRecharge);
                Student student=studentMap.get(accountRecharge.getMainAccountId());
                if (student!=null){
                    accountRechargeDetailVo.setPhoneNo(student.getPhoneNo());
                    accountRechargeDetailVo.setStudentNo(student.getStudentNo());
                }
                accountRechargeDetailVoList.add(accountRechargeDetailVo);
            }
        }
        Webs.writeExcel(request, response, AccountRechargeServiceImpl.rechargeBalance2Excel(accountRechargeDetailVoList), "充值列表");
        return ReturnResult.success("ok") ;
    }

    @ApiOperation("学生余额列表")
    @RequestMapping(value = "/studentBalancePage", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> studentBalancePage(@ModelAttribute StudentBalanceQueryVo studentBalanceQueryVo,@RequestParam("pageNo")int pageNo,@RequestParam("pageSize") int pageSize,HttpServletRequest request) {
        DataPermission dataPermission=this.getDataPermission(request);
        Page<StudentBalance> studentBalancePage = studentBalanceService.findStudentBalancePage(dataPermission,studentBalanceQueryVo, pageNo, pageSize);
        return ReturnResult.success(studentBalancePage) ;
    }

    @ApiOperation("导出学生余额列表")
    @RequestMapping(value = "/exportStudentBalance", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public ReturnResult<Void> exportStudentBalance(@ModelAttribute StudentBalanceQueryVo studentBalanceQueryVo,HttpServletRequest request,HttpServletResponse response) throws IOException {
        DataPermission dataPermission=this.getDataPermission(request);
        Webs.writeExcel(request, response, studentBalanceService.exportStudentBalance(dataPermission,studentBalanceQueryVo), "学生余额");
        return ReturnResult.success("ok") ;
    }
}
